package com.itheima.hello.TCP通信.BS架构;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

public class Server {
    public static void main(String[] args) throws Exception {
        System.out.println("服务端启动成功!");
        ServerSocket serverSocket = new ServerSocket(8080);
        //创建线程池
        ThreadPoolExecutor pool = new ThreadPoolExecutor(8 * 2, 8 * 2, 0,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(8), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());//创建线程池


        while(true){
            Socket socket = serverSocket.accept();//建立一个连接

            System.out.println("有人上线了!" + socket.getRemoteSocketAddress());
            pool.execute(new ServerReaderRunnable(socket));

        }
    }
}
